﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<WebManageUsers>" %>

<%@ Import Namespace="Common.Background.Entity" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    员工添加
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h1>
        <%= Html.ActionLink("职员管理", "WebManageUserList", "System")%>-<%= Model.ManageUserID == int.MinValue ? "添加" : "修改"%>职员</h1>
    <div>
        <%= TempData["msg"]%></div>
    <% using (Html.BeginForm())
       {%>
    <%= Html.HiddenFor(model => model.ManageUserID) %>
    <div class="tab-div">
        <table width="100%" cellspacing="1" cellpadding="3" class="chaxun_table">
            <tr>
                <td class="style1">
                    登录名
                </td>
                <td>
                    <%= Html.TextBoxFor(model => model.LoginName) %>
                    <span style="color: Red">*</span>
                    <%= Html.ValidationMessageFor(model => model.LoginName) %>
                </td>
                <td class="label" rowspan="5">
                    详细介绍
                </td>
                <td rowspan="5">
                    <%= Html.TextAreaFor(model => model.Description, new { rows = 10, cols = 30 })%>
                    <span style="color: Red">*</span>
                    <%= Html.ValidationMessageFor(model => model.Description) %>
                </td>
            </tr>
            <tr>
                <td class="style1">
                    密码
                </td>
                <td>
                    <input type="password" id="Password" name="Password" value="<%=Model.Password %>" />
                </td>
            </tr>
            <tr>
                <td class="style1">
                    邮箱
                </td>
                <td>
                    <%= Html.TextBoxFor(model => model.Email) %>
                    <span style="color: Red">*</span>
                    <%= Html.ValidationMessageFor(model => model.Email) %>
                </td>
            </tr>
            <tr>
                <td class="style1">
                    真实姓名
                </td>
                <td>
                    <%= Html.TextBoxFor(model => model.RealName) %>
                    <span style="color: Red">*</span>
                    <%= Html.ValidationMessageFor(model => model.RealName) %>
                </td>
            </tr>
            <tr>
                <td class="style1">
                    性别
                </td>
                <td>
                    <input type="radio" value="0" id="Gender0" name="Gender" <%Response.Write(Html.AttributeEncode(this.Model.Gender == "0" ? "checked=\"checked\"" : ""));%> /><label
                        for="Gender0">男</label>
                    <input type="radio" value="1" id="Gender1" name="Gender" <%Response.Write(Html.AttributeEncode(this.Model.Gender == "1" ? "checked=\"checked\"" : "")); %> /><label
                        for="Gender1">女</label>
                    <span style="color: Red">*</span>
                    <%= Html.ValidationMessageFor(model => model.Gender) %>
                </td>
            </tr>
            <tr>
                <td class="style1">
                    手机
                </td>
                <td>
                    <%= Html.TextBoxFor(model => model.Mobile) %>
                    <span style="color: Red">*</span>
                    <%= Html.ValidationMessageFor(model => model.Mobile) %>
                </td>
                <td class="label">
                    MSN号码
                </td>
                <td>
                    <%= Html.TextBoxFor(model => model.MSN) %>
                    <%= Html.ValidationMessageFor(model => model.MSN) %>
                </td>
            </tr>
            <tr>
                <td class="style1">
                    固定电话
                </td>
                <td>
                    <%= Html.TextBoxFor(model => model.Phone) %>
                    <span style="color: Red">*</span>
                    <%= Html.ValidationMessageFor(model => model.Phone) %>
                </td>
                <td class="label">
                    Rtx号码
                </td>
                <td>
                    <%= Html.TextBoxFor(model => model.Rtx) %>
                    <%= Html.ValidationMessageFor(model => model.Rtx) %>
                </td>
            </tr>
            <tr>
                <td class="style1">
                    生日
                </td>
                <td>
                    <%= Html.TextBoxFor(model => model.Birthday, new { onfocus = "WdatePicker();" })%>
                    <%--<%= Html.TextBoxFor(model => model.Birthday)%>--%>
                    <span style="color: Red">*</span>
                    <%= Html.ValidationMessageFor(model => model.Birthday) %>
                </td>
                <td class="label">
                    部门
                </td>
                <td>
                    <%= Html.ValidationMessageFor(model => model.DepartmentID) %>
                    <select name="DepartmentID" id="DepartmentID">
                        <% foreach (var i in ViewData["Departments"] as List<WebDepartments>)
                           {
                               if (i.DepartmentID == Model.DepartmentID)
                               {%>
                        <option value="<%= Html.AttributeEncode(i.DepartmentID) %>" selected="selected">
                            <%= Html.Encode(i.DepartmentName) %></option>
                        <%}
                               else
                               {%>
                        <option value="<%= Html.AttributeEncode(i.DepartmentID) %>">
                            <%= Html.Encode(i.DepartmentName)%></option>
                        <%}
                           } %>
                    </select>
                    <%= Html.ActionLink("刷新", "DepartmentForRole", Model.DepartmentID, new { id = "refreshRoles" })%>
                    状态：<%=Html.StatusForSelectList(Model.Status) %>
                </td>
            </tr>
            <tr>
                <td class="style1">
                    职位
                </td>
                <td id="roleList">
                    <%= Html.Partial("DepartmentForRole", ViewData["WebManageUser_WebManageRoles"])%>
                    <input type="button" value="添加职位" id="addRole" />
                </td>
                <td class="label">
                    QQ号码
                </td>
                <td>
                    <%= Html.TextBoxFor(model => model.QQ) %>
                    <%= Html.ValidationMessageFor(model => model.QQ) %>
                </td>
            </tr>
            <tr>
                <td>
                    已选的职位
                </td>
                <td id="selRole">
                    <% if (Model.WebManageUser_WebManageRoles_Extend != null && Model.WebManageUser_WebManageRoles_Extend.Count() > 0)
                       {
                           foreach (var item in Model.WebManageUser_WebManageRoles_Extend.ToList())
                           {
                    %>
                    <span style='display: block' id='row<%=item.ManageRoleID %>'>
                        <%=item.WebManageRoles_Extend.RoleName%>
                        <input type='hidden' name='selRoleList' value='<% =item.ManageRoleID%>' />&nbsp;&nbsp;
                        <a href='javascript:removeRow("<%=item.ManageRoleID %>")'>[移除]</a></span>
                    <%}
                       } %>
                </td>
            </tr>
            <%--  <tr>
                <td>
                    操作权限
                </td>
                <td>
                    <%=Html.UserOperationForCheckBox(Model.WebManageUser_WebManageRoles_Extend.Sum(i=>i.OperatorAuthority)) %>
                </td>
            </tr>--%>
            <tr>
                <td class="style1" rowspan="3">
                    <%if (string.IsNullOrEmpty(Model.AvatarUrl) && string.IsNullOrEmpty(Request["AvatarUrl"]))
                      { %>
                    <img id="headpic" class="seller_t2" src="http://img1.c2cedu.com/image/myc2cedu/images/touxiang2.gif"
                        width="80" height="80" alt="头像" />
                    <%}
                      else
                      { %>
                    <img id="headpic" class="seller_t2" src="<%=Model.AvatarUrl %>" width="80" height="80"
                        alt="头像" />
                    <%} %>
                </td>
                <td>
                    &nbsp;
                </td>
                <td class="label">
                    老师介绍
                </td>
                <td>
                    <%= Html.TextBoxFor(model => model.IntroductionURL,new {style="width:220px;"})%>
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;
                </td>
                <td class="label">
                    &nbsp;
                </td>
                <td>
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td>
                    <input type="hidden" id="AvatarUrl" name="AvatarUrl" value="<%=Model.AvatarUrl %>" />
                    <iframe src='<%=Url.Action("uploadheadpic","system") %>' scrolling="no" id='Iframe1' style="width: 355px;
                        height: 22px" frameborder="0"></iframe>
                </td>
                <td class="label">
                    &nbsp;
                </td>
                <td>
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td class="style1">
                </td>
                <td>
                    <% if (Model.ManageUserID == int.MinValue)
                       { %>
                    <input type="submit" value="添加" class="button" />
                    <%}
                       else
                       { %>
                    <input type="submit" value="修改" class="button" />
                    <%} %>
                </td>
            </tr>
        </table>
    </div>
    <% } %>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ScriptContent" runat="server">
    <script src="../../Scripts/jquery.validate.js" type="text/javascript"></script>
    <script src="../../Scripts/My97DatePicker4.7/WdatePicker.js" type="text/javascript"></script>
    <script type="text/javascript">

        /* 控制子页面的图像 */
        function hideLoading() {
            $('#Iframe1').show();
            $('#loadingPic').hide();
        }
        function showLoading() {
            $('#Iframe1').hide();
            $('#loadingPic').show();
        }
        function changePic(data) {
            if (data.result == true) {
                $('#AvatarUrl').val(data.msg);
                $("#headpic").attr('src', data.msg);
            }
            else {
                alert(data.msg);
            }


        }
    </script>
    <script type="text/javascript">
        function removeRow(id) {
            $("#row" + id).remove();
        }
        $(document).ready(function () {

            $("#addRole").click(function () {
                var sel = "";
                $.each($("#roleList").find("input[type=checkbox][checked=true]"), function (i, o) {
                    if ($("#selRole").find("span[id$='" + $(o).val() + "']").size() == 0)//不把重复的记录加到表格行中
                    {
                        sel = $(o).next("Label").text();
                        if ($(o).next("Label").text() == "")
                            sel = $(o).next("font").find("Label").first().text();
                        $("#selRole").append("<span style='display:block' id='row" + $(o).val() + "'>" + sel + "<input type='hidden' name='selRoleList' value='" + $(o).val() + "'>&nbsp;&nbsp;<a href=javascript:removeRow(" + $(o).val() + ")>[移除]</a></span>");
                    }
                })
            });

            var href = $("#refreshRoles").hide();
            $("#DepartmentID").bind("change", function () {
                var option = { sender: this, url: href.attr("href") };

                $.ajax({ url: option.url, data: "DeptId=" + option.sender.value, type: "post", success: function (e, t, x) {
                    $("#UserRoles").html(e);
                }
                });

                $("#UserRoles").load();
            });

            /* jquery.validate框架，表单验证 */
            $("form").validate({ messages: {
                LoginName: {
                    required: "请输入用户登陆名",
                    minlength: "职员登陆名至少为2字符，最多为20个字符",
                    maxlength: "职员登陆名至少为2字符，最多为20个字符"
                },


                Email: {
                    email: "请输入正确的邮箱地址",
                    required: "请输入正确的邮箱地址"
                },
                RealName: {
                    required: "请输入用户的真实姓名",
                    minlength: "职员的真实姓名至少为2字符，最多为20个字符",
                    maxlength: "职员的真实姓名至少为2字符，最多为20个字符"
                },
                Gender: {
                    required: "请选择用户性别"
                },
                Mobile: {
                    required: "请输入手机号码",
                    number: "手机号码必须是数字"
                },
                Phone: {
                    required: "请输入电话号码",
                    minlength: "电话号码至少为2字符，最多为20个字符",
                    maxlength: "电话号码至少为2字符，最多为20个字符"
                },
                Birthday: {
                    required: "请选择职员生日",
                    dateISO: "职员生日格式不正确"
                },
                Description: {
                    required: "请输入详细介绍",
                    minlength: "详细介绍至少为2字符，最多1000字符",
                    maxlength: "详细介绍至少为2字符，最多1000字符"
                }
            }, rules: {
                LoginName: {
                    required: true,
                    minlength: 2,
                    maxlength: 20
                },


                Email: {
                    email: true
                },
                RealName: {
                    required: true,
                    minlength: 2,
                    maxlength: 20
                },
                Gender: {
                    required: true
                },
                Mobile: {
                    required: true,
                    number: true
                },
                Phone: {
                    required: true,
                    minlength: 2,
                    maxlength: 20
                },
                Birthday: {
                    required: true,
                    dateISO: true
                },
                Description: {
                    required: true,
                    minlength: 2,
                    maxlength: 1000
                }
            }
            });
        });

    </script>
    <style type="text/css">
        .style1 { width: 104px; }
    </style>
</asp:Content>
